# 读取数据文件
import json
from pyecharts.charts import *
from pyecharts.options import *

file = open("E:/storage/study/Python/python-learn/day01/02-python-learn/10_可视化案例/素材/疫情.txt", "r", encoding="UTF-8")
# 读取全部数据
data = file.read()
# 关闭文件
file.close()
data_dic = json.loads(data)

city_data = data_dic["areaTree"][0]["children"]

city_list = []
for province in city_data:
    if province['name'] == "河南":
        for city in province["children"]:
            city_name = city["name"]+"市"
            city_confirm = city['total']['confirm']
            city_list.append((city_name,city_confirm))

city_list.append(("济源市", 5))
map = Map()
map.add("河南省确诊人数", city_list, '河南')
print(city_list)

# 设置全局配置，定制分段的视觉映射
map.set_global_opts(
    visualmap_opts = VisualMapOpts(
        is_show=True, # 是否显示
        is_piecewise=True, # 是否分段
        pieces=[
            {"min": 0, "max": 99, "label": "0-99人", "color": 'green'},
            {"min": 100, "max": 999, "label": "100-999人", "color": '#CCFFFF'},
            {"min": 1000, "max": 5000, "label": "1000-5000人", "color": 'yellow'},
            {"min": 5000, "max": 9999, "label": "5000-9999人", "color": 'blue'},
            {"min": 10000, "max": 99999, "label": "10000-99999人", "color": 'red'},
            {"min": 100000, "label": "100000人以上", "color": 'pink'}
        ]
    )
)

# 绘图
map.render("河南省疫情地图.html")